package cn.kgc.watch.web;

import cn.kgc.watch.entity.CommoditySku;
import cn.kgc.watch.entity.ProductComments;
import cn.kgc.watch.entity.ResultInfo;
import cn.kgc.watch.service.ProductCommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;
@RestController
@CrossOrigin
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private ProductCommentsService productCommentsService;
    //根据商品Id 查询商品
    @GetMapping("commentList")
    public ResultInfo findComments(Integer skuId){
        List<ProductComments> productCommentsList = this.productCommentsService.selectById(skuId);
        return new ResultInfo<>(200,"查询成功",productCommentsList);
    }
    //根据userId 查询是否购买此商品
    public ResultInfo findOrder(Integer id){
        List<ProductComments> productCommentsList=this.productCommentsService.findOrder(id);
        return new ResultInfo(200,"查询成功",productCommentsList);
    }
    //新增评论
    @PostMapping("/addComment")
    public ResultInfo addComment(@RequestBody ProductComments productComments){
        productComments.setCommentsTime(new Date());
        productComments.setModifyTime(new Date());
        System.out.println("productComments = " + productComments);
        this.productCommentsService.add(productComments);
        return new ResultInfo(200,"添加成功审核后会分布");
    }
    //根据userId 获取购买的所有商品
    @GetMapping("/findOrder")
    public ResultInfo findByUserId(Integer id){
        List<CommoditySku> commoditySkuList=this.productCommentsService.selectOrderSku(id);
        return new ResultInfo<>(200,"查询成功",commoditySkuList);
    }
    //后台审核评论
    @GetMapping("/modify")
    public ResultInfo modify(Integer commentId){
        this.productCommentsService.modify(commentId);
        return new ResultInfo(200,"通过审核");
    }
}
